using ICommonLibrary.Service;

namespace ICommonLibrary.Security {

    public class CipherService : ServiceBase, ICipherService {

        public Cipher Cipher { get; set; }

        public CipherService() {
        }

        protected override void OnInit() {
            Asserts.NotNull(Cipher, "Cipher has not been specified.");
        }

        protected override void OnStart() {
        }

        protected override void OnStop() {
        }

        protected override void OnDestroy() {
            Cipher = null;
        }

        public string Encrypt(string text) {
            Asserts.NotNull(Cipher, "cipher has not been initialized");
            return Cipher.EncryptToBase64(text);
        }

        public string Decrypt(string text) {
            Asserts.NotNull(Cipher, "cipher has not been initialized");
            return Cipher.DecryptFromBase64(text);
        }

    }
}